package com.central.common.feign;

import com.central.common.constant.ServiceNameConstants;
import com.central.common.feign.fallback.UserAccountServiceFallbackFactory;
import com.central.common.model.LoginAppUser;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * 使用 feign 调用接口,就像 controller 中配置的一样,
 * name: 指向要调用的服务, 注意要和注册中心配置的服务名称一致
 * fallbackFactory: 降级工厂,调用失败的定义,全局配置, 也可以在每个方法上定义各自的降级策略.
 * @author ly
 * @email 664162337@qq.com
 * @date 2020/9/25 15:00
 */
@FeignClient(name = ServiceNameConstants.USER_SERVICE, fallbackFactory = UserAccountServiceFallbackFactory.class, decode404 = true)
public interface UserAccountService {

    /**
     * feign rpc访问远程/accounts/{username}接口
     * 查询用户实体对象SysUserAccount
     *
     * @param username
     * @return
     */
    @GetMapping(value = "/accounts/username/{username}")
    LoginAppUser findByUsername(@PathVariable("username") String username);

    /**
     * 通过userid属性获取用户信息
     * @param userId
     * @return
     */
    @GetMapping("/accounts/{userId}")
    LoginAppUser findByUserId(@PathVariable("userId") String userId);
}
